home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0065_Another Bits example.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  904b  |  36 lines

  1.  
  2. {
  3.  I'll give a little program to demonstrate testing bits of a word for
  4.  being set or clear.  The BitIsSet function can be coded a little more
  5.  efficiently, but I suspect you want clarity, not programming tricks.
  6. }
  7.  
  8. Program BitExample;
  9. var
  10.   testword : word;
  11.   i        : word;
  12.  
  13. (*
  14.   Function BitIsSet. Given 'Wd', a word, and 'Bit', a bit number from
  15.   0 through 15, return true if the bit number of the word is
  16.   set, else return false.
  17. *)
  18. function BitIsSet(Wd:word; Bit:byte): boolean;
  19.   begin
  20.     if ((Wd shr Bit) and $01) <> 0 then
  21.       BitIsSet := true
  22.      else
  23.       BitIsSet := false;
  24.   end; {bitisset}
  25.  
  26. begin {program}
  27.   testword := $805F;
  28.   for i := 0 to 15 do
  29.     begin
  30.       if BitIsSet(testword,i) then
  31.         writeln( 'Testword bit ',i:2,' is set.' )
  32.        else
  33.         writeln( 'Testword bit ',i:2,' is clear.' )
  34.     end;
  35. end. {program bitexample}
  36.